package com.gitee.feizns.quickstart.web.decrypt;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.gitee.feizns.quickstart.spring.AppUtils;

import java.io.IOException;

/**
 * Jackson解密反序列化处理器
 * @see Decrypt
 * @author feizns
 * @since 2023/2/4
 */
public class DecryptStdDeserializer extends StdDeserializer<String> {

    public DecryptStdDeserializer() {
        super(String.class);
    }

    @Override
    public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        DecryptionAlgorithm algorithm = AppUtils.getBean(DecryptionAlgorithm.class);
        return algorithm.decrypt(jsonParser.getValueAsString());
    }

}
